package Java.BlackHorse.a03ExceptionTest;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Person p = new Person();
        while (true) {
            try {
                System.out.println("请输入姓名：");
                String name = sc.nextLine();
                p.setName(name);
                System.out.println("请输入年龄：");
                String Personage = sc.nextLine();
                int age = Integer.parseInt(Personage);
                p.setAge(age);
                break;
            } catch (NumberFormatException e) {
                System.out.println("年龄格式输入错误");
            }catch (AgeBoundaryException e){
                e.printStackTrace();
            }catch (NameFormatException e){
                e.printStackTrace();
            }
        }
        System.out.println(p.toString());
    }
}
